package org.dashboard.utils;

import org.dashboard.constant.DbSourceTypeEnum;

public class DbTypeTools {

    public static String getDataSourceUrl(String ip, String port, String database, DbSourceTypeEnum dbType) {
        switch (dbType) {
            case MySql:
                return String.format("jdbc:mysql://%s:%s/%s?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC", ip, port, database);
            case PostgreSql:
                return String.format("jdbc:postgresql://%s:%s/%s", ip, port, database);
        }
        return "";
    }

    public static String getDataSourceDriver(DbSourceTypeEnum dbType) {
        switch (dbType) {
            case MySql:
                return "com.mysql.cj.jdbc.Driver";
            case PostgreSql:
                return "org.postgresql.Driver";
        }
        return "";
    }

    public static DbSourceTypeEnum getDataSourceEnum(Integer type) {
        switch (type) {
            case 1:
                return DbSourceTypeEnum.MySql;
            case 2:
                return DbSourceTypeEnum.PostgreSql;
        }
        return DbSourceTypeEnum.MySql;
    }
}
